package com.bawei.park2302.adapter

import android.view.View
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bawei.lib_base.utils.utils.entity.MyHouseBean
import com.bawei.park2302.R
import com.bawei.park2302.house.HouseViewModel
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class HouseAreaAdapter(vm : HouseViewModel) : BaseQuickAdapter<MyHouseBean,BaseViewHolder>(R.layout.item_house_eara){
    lateinit var vm: HouseViewModel
    init {
        this.vm = vm
    }
    override fun convert(helper: BaseViewHolder, item: MyHouseBean) {
        helper.setText(R.id.tv01,"${item.dong}栋")
        helper.setText(R.id.house_area,"${item.area}㎡")

        val houseAdapter by lazy { HouseAdapter(vm) }
        houseAdapter.addData(item.list)
        val recyclerView = helper.getView<RecyclerView>(R.id.rv_01)
        recyclerView.apply {
            adapter = houseAdapter
            layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)
        }

        helper.getView<ImageView>(R.id.more01).apply {
            setOnClickListener {
                if (recyclerView.visibility == View.GONE){
                    recyclerView.visibility=View.VISIBLE
                    setImageResource(R.drawable.ic_keyboard_arrow_up)
                }else{
                    recyclerView.visibility=View.GONE
                    setImageResource(R.drawable.ic_keyboard_arrow_down)
                }
            }
        }
    }
}